<?php

/**
 * ItemVendorDetailsByMarketplace.
 *
 * PHP version 8.3
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */

/**
 * Selling Partner API for Catalog Items.
 *
 * Use the Selling Partner API for Catalog Items to retrieve information about items in the Amazon catalog.  For more information, refer to the [Catalog Items API Use Case Guide](https://developer-docs.amazon.com/sp-api/docs/:catalog-items-api-v2022-04-01-use-case-guide).
 *
 * The version of the OpenAPI document: 2022-04-01
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.9.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace SpApi\Model\catalogItems\v2022_04_01;

use SpApi\Model\ModelInterface;
use SpApi\ObjectSerializer;

/**
 * ItemVendorDetailsByMarketplace Class Doc Comment.
 *
 * @category Class
 *
 * @description The vendor details that are associated with an Amazon catalog item for the specified &#x60;marketplaceId&#x60;.
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 *
 * @implements \ArrayAccess<string, mixed>
 */
class ItemVendorDetailsByMarketplace implements ModelInterface, \ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

    public const REPLENISHMENT_CATEGORY_ALLOCATED = 'ALLOCATED';
    public const REPLENISHMENT_CATEGORY_BASIC_REPLENISHMENT = 'BASIC_REPLENISHMENT';
    public const REPLENISHMENT_CATEGORY_IN_SEASON = 'IN_SEASON';
    public const REPLENISHMENT_CATEGORY_LIMITED_REPLENISHMENT = 'LIMITED_REPLENISHMENT';
    public const REPLENISHMENT_CATEGORY_MANUFACTURER_OUT_OF_STOCK = 'MANUFACTURER_OUT_OF_STOCK';
    public const REPLENISHMENT_CATEGORY_NEW_PRODUCT = 'NEW_PRODUCT';
    public const REPLENISHMENT_CATEGORY_NON_REPLENISHABLE = 'NON_REPLENISHABLE';
    public const REPLENISHMENT_CATEGORY_NON_STOCKUPABLE = 'NON_STOCKUPABLE';
    public const REPLENISHMENT_CATEGORY_OBSOLETE = 'OBSOLETE';
    public const REPLENISHMENT_CATEGORY_PLANNED_REPLENISHMENT = 'PLANNED_REPLENISHMENT';

    /**
     * The original name of the model.
     */
    protected static string $openAPIModelName = 'ItemVendorDetailsByMarketplace';

    /**
     * Array of property to type mappings. Used for (de)serialization.
     *
     * @var string[]
     */
    protected static array $openAPITypes = [
        'marketplace_id' => 'string',
        'brand_code' => 'string',
        'manufacturer_code' => 'string',
        'manufacturer_code_parent' => 'string',
        'product_category' => '\SpApi\Model\catalogItems\v2022_04_01\ItemVendorDetailsCategory',
        'product_group' => 'string',
        'product_subcategory' => '\SpApi\Model\catalogItems\v2022_04_01\ItemVendorDetailsCategory',
        'replenishment_category' => 'string'];

    /**
     * Array of property to format mappings. Used for (de)serialization.
     *
     * @var string[]
     *
     * @phpstan-var array<string, string|null>
     *
     * @psalm-var array<string, string|null>
     */
    protected static array $openAPIFormats = [
        'marketplace_id' => null,
        'brand_code' => null,
        'manufacturer_code' => null,
        'manufacturer_code_parent' => null,
        'product_category' => null,
        'product_group' => null,
        'product_subcategory' => null,
        'replenishment_category' => null];

    /**
     * Array of nullable properties. Used for (de)serialization.
     *
     * @var bool[]
     */
    protected static array $openAPINullables = [
        'marketplace_id' => false,
        'brand_code' => true,
        'manufacturer_code' => true,
        'manufacturer_code_parent' => true,
        'product_category' => true,
        'product_group' => true,
        'product_subcategory' => true,
        'replenishment_category' => true,
    ];

    /**
     * If a nullable field gets set to null, insert it here.
     *
     * @var bool[]
     */
    protected array $openAPINullablesSetToNull = [];

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     *
     * @var string[]
     */
    protected static array $attributeMap = [
        'marketplace_id' => 'marketplaceId',
        'brand_code' => 'brandCode',
        'manufacturer_code' => 'manufacturerCode',
        'manufacturer_code_parent' => 'manufacturerCodeParent',
        'product_category' => 'productCategory',
        'product_group' => 'productGroup',
        'product_subcategory' => 'productSubcategory',
        'replenishment_category' => 'replenishmentCategory',
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     *
     * @var string[]
     */
    protected static array $setters = [
        'marketplace_id' => 'setMarketplaceId',
        'brand_code' => 'setBrandCode',
        'manufacturer_code' => 'setManufacturerCode',
        'manufacturer_code_parent' => 'setManufacturerCodeParent',
        'product_category' => 'setProductCategory',
        'product_group' => 'setProductGroup',
        'product_subcategory' => 'setProductSubcategory',
        'replenishment_category' => 'setReplenishmentCategory',
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests).
     *
     * @var string[]
     */
    protected static array $getters = [
        'marketplace_id' => 'getMarketplaceId',
        'brand_code' => 'getBrandCode',
        'manufacturer_code' => 'getManufacturerCode',
        'manufacturer_code_parent' => 'getManufacturerCodeParent',
        'product_category' => 'getProductCategory',
        'product_group' => 'getProductGroup',
        'product_subcategory' => 'getProductSubcategory',
        'replenishment_category' => 'getReplenishmentCategory',
    ];

    /**
     * Associative array for storing property values.
     */
    protected array $container = [];

    /**
     * Constructor.
     *
     * @param null|array $data Associated array of property values
     *                         initializing the model
     */
    public function __construct(?array $data = null)
    {
        $this->setIfExists('marketplace_id', $data ?? [], null);
        $this->setIfExists('brand_code', $data ?? [], null);
        $this->setIfExists('manufacturer_code', $data ?? [], null);
        $this->setIfExists('manufacturer_code_parent', $data ?? [], null);
        $this->setIfExists('product_category', $data ?? [], null);
        $this->setIfExists('product_group', $data ?? [], null);
        $this->setIfExists('product_subcategory', $data ?? [], null);
        $this->setIfExists('replenishment_category', $data ?? [], null);
    }

    /**
     * Gets the string presentation of the object.
     *
     * @return string
     */
    public function __toString()
    {
        return json_encode(
            ObjectSerializer::sanitizeForSerialization($this),
            JSON_PRETTY_PRINT
        );
    }

    /**
     * Array of property to type mappings. Used for (de)serialization.
     */
    public static function openAPITypes(): array
    {
        return self::$openAPITypes;
    }

    /**
     * Array of property to format mappings. Used for (de)serialization.
     */
    public static function openAPIFormats(): array
    {
        return self::$openAPIFormats;
    }

    /**
     * Checks if a property is nullable.
     */
    public static function isNullable(string $property): bool
    {
        return self::openAPINullables()[$property] ?? false;
    }

    /**
     * Checks if a nullable property is set to null.
     */
    public function isNullableSetToNull(string $property): bool
    {
        return in_array($property, $this->getOpenAPINullablesSetToNull(), true);
    }

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     */
    public static function attributeMap(): array
    {
        return self::$attributeMap;
    }

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     */
    public static function setters(): array
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests).
     */
    public static function getters(): array
    {
        return self::$getters;
    }

    /**
     * The original name of the model.
     */
    public function getModelName(): string
    {
        return self::$openAPIModelName;
    }

    /**
     * Gets allowable values of the enum.
     *
     * @return string[]
     */
    public function getReplenishmentCategoryAllowableValues(): array
    {
        return [
            self::REPLENISHMENT_CATEGORY_ALLOCATED,
            self::REPLENISHMENT_CATEGORY_BASIC_REPLENISHMENT,
            self::REPLENISHMENT_CATEGORY_IN_SEASON,
            self::REPLENISHMENT_CATEGORY_LIMITED_REPLENISHMENT,
            self::REPLENISHMENT_CATEGORY_MANUFACTURER_OUT_OF_STOCK,
            self::REPLENISHMENT_CATEGORY_NEW_PRODUCT,
            self::REPLENISHMENT_CATEGORY_NON_REPLENISHABLE,
            self::REPLENISHMENT_CATEGORY_NON_STOCKUPABLE,
            self::REPLENISHMENT_CATEGORY_OBSOLETE,
            self::REPLENISHMENT_CATEGORY_PLANNED_REPLENISHMENT,
        ];
    }

    /**
     * Show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties(): array
    {
        $invalidProperties = [];

        if (null === $this->container['marketplace_id']) {
            $invalidProperties[] = "'marketplace_id' can't be null";
        }
        $allowedValues = $this->getReplenishmentCategoryAllowableValues();
        if (!is_null($this->container['replenishment_category']) && !in_array($this->container['replenishment_category'], $allowedValues, true)) {
            $invalidProperties[] = sprintf(
                "invalid value '%s' for 'replenishment_category', must be one of '%s'",
                $this->container['replenishment_category'],
                implode("', '", $allowedValues)
            );
        }

        return $invalidProperties;
    }

    /**
     * Validate all the properties in the model
     * return true if all passed.
     *
     * @return bool True if all properties are valid
     */
    public function valid(): bool
    {
        return 0 === count($this->listInvalidProperties());
    }

    /**
     * Gets marketplace_id.
     */
    public function getMarketplaceId(): string
    {
        return $this->container['marketplace_id'];
    }

    /**
     * Sets marketplace_id.
     *
     * @param string $marketplace_id Amazon marketplace identifier. To find the ID for your marketplace, refer to [Marketplace IDs](https://developer-docs.amazon.com/sp-api/docs/marketplace-ids).
     */
    public function setMarketplaceId(string $marketplace_id): self
    {
        if (is_null($marketplace_id)) {
            throw new \InvalidArgumentException('non-nullable marketplace_id cannot be null');
        }
        $this->container['marketplace_id'] = $marketplace_id;

        return $this;
    }

    /**
     * Gets brand_code.
     */
    public function getBrandCode(): ?string
    {
        return $this->container['brand_code'];
    }

    /**
     * Sets brand_code.
     *
     * @param null|string $brand_code the brand code that is associated with an Amazon catalog item
     */
    public function setBrandCode(?string $brand_code): self
    {
        if (is_null($brand_code)) {
            array_push($this->openAPINullablesSetToNull, 'brand_code');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('brand_code', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['brand_code'] = $brand_code;

        return $this;
    }

    /**
     * Gets manufacturer_code.
     */
    public function getManufacturerCode(): ?string
    {
        return $this->container['manufacturer_code'];
    }

    /**
     * Sets manufacturer_code.
     *
     * @param null|string $manufacturer_code the manufacturer code that is associated with an Amazon catalog item
     */
    public function setManufacturerCode(?string $manufacturer_code): self
    {
        if (is_null($manufacturer_code)) {
            array_push($this->openAPINullablesSetToNull, 'manufacturer_code');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('manufacturer_code', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['manufacturer_code'] = $manufacturer_code;

        return $this;
    }

    /**
     * Gets manufacturer_code_parent.
     */
    public function getManufacturerCodeParent(): ?string
    {
        return $this->container['manufacturer_code_parent'];
    }

    /**
     * Sets manufacturer_code_parent.
     *
     * @param null|string $manufacturer_code_parent the parent vendor code of the manufacturer code
     */
    public function setManufacturerCodeParent(?string $manufacturer_code_parent): self
    {
        if (is_null($manufacturer_code_parent)) {
            array_push($this->openAPINullablesSetToNull, 'manufacturer_code_parent');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('manufacturer_code_parent', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['manufacturer_code_parent'] = $manufacturer_code_parent;

        return $this;
    }

    /**
     * Gets product_category.
     */
    public function getProductCategory(): ?ItemVendorDetailsCategory
    {
        return $this->container['product_category'];
    }

    /**
     * Sets product_category.
     *
     * @param null|ItemVendorDetailsCategory $product_category product_category
     */
    public function setProductCategory(?ItemVendorDetailsCategory $product_category): self
    {
        if (is_null($product_category)) {
            array_push($this->openAPINullablesSetToNull, 'product_category');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('product_category', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['product_category'] = $product_category;

        return $this;
    }

    /**
     * Gets product_group.
     */
    public function getProductGroup(): ?string
    {
        return $this->container['product_group'];
    }

    /**
     * Sets product_group.
     *
     * @param null|string $product_group the product group that is associated with an Amazon catalog item
     */
    public function setProductGroup(?string $product_group): self
    {
        if (is_null($product_group)) {
            array_push($this->openAPINullablesSetToNull, 'product_group');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('product_group', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['product_group'] = $product_group;

        return $this;
    }

    /**
     * Gets product_subcategory.
     */
    public function getProductSubcategory(): ?ItemVendorDetailsCategory
    {
        return $this->container['product_subcategory'];
    }

    /**
     * Sets product_subcategory.
     *
     * @param null|ItemVendorDetailsCategory $product_subcategory product_subcategory
     */
    public function setProductSubcategory(?ItemVendorDetailsCategory $product_subcategory): self
    {
        if (is_null($product_subcategory)) {
            array_push($this->openAPINullablesSetToNull, 'product_subcategory');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('product_subcategory', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['product_subcategory'] = $product_subcategory;

        return $this;
    }

    /**
     * Gets replenishment_category.
     */
    public function getReplenishmentCategory(): ?string
    {
        return $this->container['replenishment_category'];
    }

    /**
     * Sets replenishment_category.
     *
     * @param null|string $replenishment_category the replenishment category that is associated with an Amazon catalog item
     */
    public function setReplenishmentCategory(?string $replenishment_category): self
    {
        if (is_null($replenishment_category)) {
            array_push($this->openAPINullablesSetToNull, 'replenishment_category');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('replenishment_category', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $allowedValues = $this->getReplenishmentCategoryAllowableValues();
        if (!is_null($replenishment_category) && !in_array($replenishment_category, $allowedValues, true)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value '%s' for 'replenishment_category', must be one of '%s'",
                    $replenishment_category,
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['replenishment_category'] = $replenishment_category;

        return $this;
    }

    /**
     * Returns true if offset exists. False otherwise.
     *
     * @param int $offset Offset
     */
    public function offsetExists($offset): bool
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     *
     * @param int $offset Offset
     *
     * @return null|mixed
     */
    #[\ReturnTypeWillChange]
    public function offsetGet($offset): mixed
    {
        return $this->container[$offset] ?? null;
    }

    /**
     * Sets value based on offset.
     *
     * @param null|int $offset Offset
     * @param mixed    $value  Value to be set
     */
    public function offsetSet($offset, mixed $value): void
    {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }

    /**
     * Unsets offset.
     *
     * @param int $offset Offset
     */
    public function offsetUnset($offset): void
    {
        unset($this->container[$offset]);
    }

    /**
     * Serializes the object to a value that can be serialized natively by json_encode().
     *
     * @see https://www.php.net/manual/en/jsonserializable.jsonserialize.php
     *
     * @return mixed returns data which can be serialized by json_encode(), which is a value
     *               of any type other than a resource
     */
    #[\ReturnTypeWillChange]
    public function jsonSerialize(): mixed
    {
        return ObjectSerializer::sanitizeForSerialization($this);
    }

    /**
     * Gets a header-safe presentation of the object.
     */
    public function toHeaderValue(): string
    {
        return json_encode(ObjectSerializer::sanitizeForSerialization($this));
    }

    /**
     * Array of nullable properties.
     */
    protected static function openAPINullables(): array
    {
        return self::$openAPINullables;
    }

    /**
     * Array of nullable field names deliberately set to null.
     *
     * @return bool[]
     */
    private function getOpenAPINullablesSetToNull(): array
    {
        return $this->openAPINullablesSetToNull;
    }

    /**
     * Setter - Array of nullable field names deliberately set to null.
     *
     * @param bool[] $openAPINullablesSetToNull
     */
    private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
    {
        $this->openAPINullablesSetToNull = $openAPINullablesSetToNull;
    }

    /**
     * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
     * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
     * $this->openAPINullablesSetToNull array.
     *
     * @param mixed $defaultValue
     */
    private function setIfExists(string $variableName, array $fields, $defaultValue): void
    {
        if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
            $this->openAPINullablesSetToNull[] = $variableName;
        }

        $this->container[$variableName] = $fields[$variableName] ?? $defaultValue;
    }
}
